package com.aigua.advice;

import com.aigua.exception.IncorrectPasswordException;
import com.aigua.exception.OrderNotFoundException;
import com.aigua.exception.UserNotFoundException;
import com.aigua.vo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @RestControllerAdvice: 拦截所有带有@RestController注解的类
 * @TODO:
 * @Author:baimu
 * @Date:2024 04 01 09 50
 **/



@RestControllerAdvice
@Slf4j
public class ExceptionAdvice {

   @ExceptionHandler(value = UserNotFoundException.class)
    public CommonResult handleUserNotFoundException(Exception e){
       log.info("用户名不存在");
       return CommonResult.fail(e.getMessage());
   }

    @ExceptionHandler(value = IncorrectPasswordException.class)
    public CommonResult handleIncorrectPasswordException(Exception e){
        return CommonResult.fail(e.getMessage());
    }

    @ExceptionHandler(value = OrderNotFoundException.class)
    public CommonResult handleOrderNotFoundException(Exception e){
        return CommonResult.fail(e.getMessage());
    }



}
